/**
 * Charts1：仪表盘
 */
import React  from 'react'
import style from './index.less'
import {Button,Icon} from 'antd'

export default class FeedTool extends React.Component{
  state = {
    upvoteNum:parseInt(this.props.upvote),
    upvote: parseInt(this.props.user_upvote),
    downvote:parseInt(this.props.user_downvote),
    collect:parseInt(this.props.user_collect),
    nohelp:parseInt(this.props.user_nohelp),
  };

  changeUpVote = ()=>{
    const value=this.state.upvote
      if(value){
        this.setState({
          upvote:false,
          upvoteNum:this.state.upvoteNum-1,
        })
      }else{
        _paq.push(['trackEvent','投顾界面',	this.props.article_id	,'点赞',	this.props.trader]);
        this.setState({
          upvote:true,
          upvoteNum:this.state.upvoteNum+1,
          downvote:false,
        })
      }
      this.props.articleFeedCollect({
        article_id:this.props.article_id*1,
        action:'upvote',
      })
  }

  changeDownVote = ()=>{
    const value=this.state.downvote
      if(value){
        this.setState({
          downvote:false
        })
      }else{
        _paq.push(['trackEvent','投顾界面',	this.props.article_id	,'踩',	this.props.trader]);
        this.setState({
          downvote:true,
          upvoteNum:this.state.upvote?this.state.upvoteNum-1:this.state.upvoteNum,
          upvote:false,
        })
      }
      this.props.articleFeedCollect({
        article_id:this.props.article_id*1,
        action:'downvote',
      })
  }

  changeCollect = ()=>{
    if(!this.state.collect){
      _paq.push(['trackEvent','投顾界面',	this.props.article_id	,'收藏',	this.props.trader]);
    }
    this.setState({
      collect:!this.state.collect
    })
    this.props.articleFeedCollect({
      article_id:this.props.article_id*1,
      action:'collect',
    })
  }

  // changeNohelp = ()=>{
  //   this.setState({
  //     nohelp:!this.state.nohelp
  //   })
  //   this.props.articleFeedCollect({
  //     article_id:this.props.article_id*1,
  //     action:'nohelp',
  //   })
  // }

  render(){
    return (
      <div className={style.tool}>
        <Button onClick={this.changeUpVote} type={this.state.upvote?'primary':''}><Icon type="caret-up" /> {this.state.upvoteNum}</Button>
        <Button onClick={this.changeDownVote} type={this.state.downvote?'primary':''}><Icon type="caret-down" /></Button>
        <Button onClick={this.changeCollect} type={this.state.collect?'primary':''}><Icon type="star" /> 收藏</Button>
        {/* <Button onClick={this.changeNohelp} type={this.state.nohelp?'primary':''}><Icon type="dislike" /> 没有帮助</Button> */}
      </div>
    )
  }
}
